home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Storage / DragPriv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  20.3 KB  |  683 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DragPriv.cpp
  3.  
  4.     Contains:    Implementation of Private classes for ODDragAndDrop.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <14>      10/22/96    DH        1382560    • The 'hfs ' flavor in Drag and
  13.                                     Drop should be the lowest fidelity kind.
  14.                                     Reverse order of MacOS scrap kind info and
  15.                                     hfs info.
  16.         <13>     9/26/96    CC        1390741 - ODMemDragItem destructor:
  17.                                     ClearAllPromises now performed by storage
  18.                                     unit.
  19.         <12>    20.09.1996    NP        1386078: GetXXXContainer should be
  20.                                     AcquireXXXContainer in StorUtil
  21.         <11>     9/19/96    DH        Task: low memory changes.Suppress fatal
  22.                                     Bento errors during low-mem D&D problems.
  23.         <10>     7/18/96    DH        #136990:Drags don't contain all types. Now
  24.                                     correctly counts drag item flavors.
  25.          <9>     7/11/96    DH        1365986    1.1GM: Crash when drag fails and
  26.                                     another drag is attempted. Fixed many stale
  27.                                     object references.
  28.          <8>     6/21/96    DH        1353507: 1.0.x: Dragging Scrapbook OpenDoc
  29.                                     clipping to document can cause crash.
  30.          <6>     5/23/96    DH        1344338: Force quit of document when
  31.                                     dragging 'Bad' file or Container. Turned
  32.                                     off fatal Bento errors for Open and Create
  33.                                     container operations.
  34.          <5>     5/15/96    DH        Removed bogus include so that will build
  35.                                     will not be broken!
  36.          <4>     5/13/96    DH        1305572 - 1.1MRD:[Cyberdog]Dragging
  37.                                     multiple items *really* slow.
  38.                                     1314704 - 1.0.x: Enourmous performance hit
  39.                                     when dragging numb erous items over
  40.                                     windows.
  41.          <3>      5/1/96    JA        1314704: Allow ODMemDragItem to use
  42.                                     pre-existing container.
  43.          <2>     3/15/96    DH        1287259 - 1.0.2 Don't get back what I put
  44.                                     in the scrapbook. Changed ODMemContainer so
  45.                                     that it has a constructor that makes a new
  46.                                     container given a container handle.
  47.         <27>    10/13/95    EL        1287340: Use standard ISO prefix
  48.         <26>     10/4/95    jpa        Added missing ODVolatiles [1285799]
  49.         <25>     10/4/95    VL        1287585: Check to see whether we are
  50.                                     dragging a folder before getting the file
  51.                                     info.
  52.         <24>     9/13/95    VL        1283523: Stop copying names for stationery
  53.                                     files.
  54.         <23>      9/8/95    VL        1274572: Preserved the curResFile in
  55.                                     GetIconFamilyFromFile.
  56.         <22>      9/8/95    TÇ        1281096 FB2:Many constants in ODTypesB
  57.                                     without kOD prefix!
  58.         <21>      9/6/95    VL        1274572: Added GetFinderInfo and
  59.                                     GetIconFamilyFromFile.
  60.         <20>     8/12/95    TÇ        1276812 Need to use TempObjs and TempRefs
  61.                                     for exception safety and to avoid TRY
  62.                                     blocks, 1276807 Opt./Bug: use StdTypIO
  63.                                     routines for portable streaming & smaller
  64.                                     footprint
  65.         <19>     7/26/95    VL        1270320: ClearAllPromises when deleting
  66.                                     memory container.
  67.         <18>     5/26/95    VL        1251403: Multithreading naming support.
  68.         <17>     5/25/95    jpa        Fixed usage of ODDebug. [1253321]
  69.         <16>     4/25/95    VL        1240737: Make sure that ID for file
  70.                                     container is set to the right _length.
  71.         <15>     4/15/95    VL        1240014: turned off debug statements.
  72.         <14>     4/14/95    VL        Temporarily turned on debug printf.
  73.         <13>     3/10/95    VL        1227218: Get rid of system heap.
  74.         <12>     2/27/95    VL        1198037: Removed debugstr from code.
  75.         <11>     2/10/95    VL        1205627: Used kODBentoUpdateContainer.
  76.         <10>     1/26/95    VL        #???: Use updated Storage Unit Ref API.
  77.          <9>     1/19/95    CC        1212419 Pass kODBentoMemoryContainer to
  78.                                     CreateMemoryContainer & GetMemoryContainer.
  79.          <8>    12/20/94    VL        1195012: Make Storage calls be
  80.                                     marshallable.
  81.          <7>    12/13/94    VL        1203627,1200603,1203451,1198037,1194537,119
  82.                                     4755,1186815: Bug fixes.
  83.          <6>     9/23/94    VL        1184272: ContainerID is now a sequence of
  84.                                     octets.
  85.          <5>     8/26/94    VL        1183174: Use updated cloning APIs
  86.                                     (specifically GetStorageUnitRef takes ID
  87.                                     now).
  88.          <4>     8/15/94    TÇ        #1180922 Removed most obsolete types from
  89.                                     StdTypes.idl
  90.          <3>      8/3/94    VL        1153123: Storage to ODStor.
  91.          <2>     7/26/94    VL        Got rid of dependency on Bento.
  92.          <1>     7/21/94    VL        first checked in
  93.  
  94.     To Do:
  95.     In Progress:
  96.         
  97. */
  98.  
  99. #ifndef _DRAGPRIV_
  100. #include <DragPriv.h>
  101. #endif
  102.  
  103. #ifndef _BENTOSUPPRESS_
  104. #include "BentoSuppress.h"
  105. #endif
  106.  
  107. #ifndef SOM_ODStorageSystem_xh
  108. #include <ODStor.xh>
  109. #endif
  110.  
  111. #ifndef SOM_ODContainer_xh
  112. #include <ODCtr.xh>
  113. #endif
  114.  
  115. #ifndef SOM_ODDocument_xh
  116. #include <Document.xh>
  117. #endif
  118.  
  119. #ifndef SOM_ODDraft_xh
  120. #include <ODDraft.xh>
  121. #endif
  122.  
  123. #ifndef SOM_ODStorageUnit_xh
  124. #include <StorageU.xh>
  125. #endif
  126.  
  127. #ifndef _ODMEMORY_
  128. #include "ODMemory.h"
  129. #endif
  130.  
  131. #ifndef _STDTYPIO_
  132. #include "StdTypIO.h"
  133. #endif
  134.  
  135. #ifndef _TEMPOBJ_
  136. #include "TempObj.h"
  137. #endif
  138.  
  139. #ifndef SOM_Module_OpenDoc_StdProps_defined
  140. #include <StdProps.xh>
  141. #endif
  142.  
  143. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  144. #include <StdTypes.xh>
  145. #endif
  146.  
  147. #ifndef SOM_ODTranslation_xh
  148. #include <Translt.xh>
  149. #endif
  150.  
  151. #ifndef _STORUTIL_
  152. #include <StorUtil.h>
  153. #endif
  154.  
  155. #ifndef _BARRAY_
  156. #include <BArray.h>
  157. #endif
  158.  
  159. #ifndef _ISOSTR_
  160. #include <ISOStr.h>
  161. #endif
  162.  
  163. #ifndef _INFOUTIL_
  164. #include <InfoUtil.h>
  165. #endif
  166.  
  167. #ifndef _ICONS_
  168. #include <Icons.h>
  169. #endif
  170.  
  171. #ifndef _PLFMFILE_
  172. #include <PlfmFile.h>
  173. #endif
  174.  
  175. #ifndef _USERSRCM_
  176. #include <UseRsrcM.h>
  177. #endif
  178.  
  179. #ifndef __FINDER__
  180. #include <Finder.h>
  181. #endif
  182.  
  183. #ifndef _CONSTDEF_
  184. #include "ConstDef.h"
  185. #endif
  186.  
  187. //#ifndef _BENTOSUPPRESS_
  188. //#include <BentoSuppress.h>
  189. //#endif
  190.  
  191. #if ODDebug
  192. #ifndef __STRINGS__
  193. #include <Strings.h>
  194. #endif
  195. #endif
  196.  
  197. #if ODDebug
  198. // #define ODDebug_DragPriv    1
  199. #endif
  200.  
  201. const ODContainerType kODBentoUpdateContainer = "+//ISO 9070/ANSI::113722::US::CI LABS::OpenDoc:Bento Container Suite:ContainerType:Update";
  202.  
  203. //==============================================================================
  204. // Function Prototype
  205. //==============================================================================
  206.  
  207. ODContainerType    GetContainerSuiteType(FSSpec* fsSpec);
  208.  
  209. //==============================================================================
  210. // ODDragItem
  211. //==============================================================================
  212. //------------------------------------------------------------------------------
  213. // ODDragItem::ODDragItem
  214. //------------------------------------------------------------------------------
  215. ODDragItem::ODDragItem(ODStorageSystem *storage, ODBoolean IsForeignDataSU,
  216.                                 ODPlatformDragReference currentDrag,
  217.                                 ItemReference theDragItemRefNumber,
  218.                                 HFSFlavor*    hfsFlavor)
  219. {
  220.     fStorageSystem                 = storage;
  221.     fCurrentDragItemRefNumber    = theDragItemRefNumber;
  222.     fCurrentDrag                 = currentDrag;
  223.     fHFSFlavorPtr                 = hfsFlavor;
  224.  
  225.     fContainer = kODNULL;
  226.     fDocument = kODNULL;
  227.     fDraft = kODNULL;
  228.     fSU = kODNULL;
  229. }
  230.  
  231. //------------------------------------------------------------------------------
  232. // ODDragItem::Open
  233. //------------------------------------------------------------------------------
  234. void ODDragItem::Open(Environment* ev)
  235. {
  236.     WARN("ODDragItem::Open should not be called.");
  237. }
  238.  
  239.  
  240. //------------------------------------------------------------------------------
  241. // ODDragItem::Close
  242. //------------------------------------------------------------------------------
  243. void ODDragItem::Close(Environment* ev)
  244. {
  245.     WARN("ODDragItem::Open should not be called.");
  246. }
  247.  
  248. //------------------------------------------------------------------------------
  249. // ODDragItem::AddFinderInfoToSU
  250. //------------------------------------------------------------------------------
  251. void ODDragItem::AddFinderInfoToSU( Environment* ev )
  252. {
  253.     // Integrating code from EnterHandler to now generate Finder Info here.
  254.  
  255.     // If the drag item was an HFS flavor, then write out the Finder info here
  256.     // so that a part could mimic the Finder and have all  of the Finder
  257.     // info available to it. Otherwise, parts have not have enough info
  258.     // to deal with Finder files.
  259.  
  260.     TRY
  261.         if ( fHFSFlavorPtr != kODNULL )
  262.         {
  263.             TempPlatformFile finderFile = new PlatformFile;
  264. //            finderFile = new PlatformFile();
  265.             finderFile->Specify(&(fHFSFlavorPtr->fileSpec));
  266.         
  267.             GetFinderInfo(ev, fSU, finderFile);
  268.             GetIconFamilyFromFile(ev, fSU, finderFile);
  269.         }
  270.     CATCH_ALL
  271.         // If the drag item is not a finder file, like from the Scrapbook,
  272.         // then we don't have anything to add. Therefor, don't reraise if there
  273.         // are exceptions.
  274.     ENDTRY
  275. }
  276.  
  277. //------------------------------------------------------------------------------
  278. // ODDragItem::AddMacOSTypeInfoToSU
  279. //------------------------------------------------------------------------------
  280. void ODDragItem::AddMacOSTypeInfoToSU( Environment* ev )
  281. {
  282.     // Now add old-style MacOS kinds to the SU, if kinds were dragged from a non-OpenDoc
  283.     // process. Otherwise, don't need to do anything.
  284.     
  285.     if( fCurrentDrag != 0 )
  286.     {
  287.         // Go through all of the flavors in the drag item, and add an ISO kind to the
  288.         // storage unit. These will constitute the multiple kinds that a drag
  289.         // might have. For example, if an app wrote out TEXT and STYL kinds, we want
  290.         // those both to be available to a part in the data transfer SU.
  291.         ODUShort            numDragFlavors = 0;
  292.         ODTranslation*        translation         = fStorageSystem->GetSession(ev)->GetTranslation(ev);
  293.         CountDragItemFlavors(fCurrentDrag, fCurrentDragItemRefNumber, &numDragFlavors);
  294.         
  295.         for ( ODUShort dragFlavorIndex = 1; dragFlavorIndex <= numDragFlavors; dragFlavorIndex++)
  296.         {
  297.             OSType        theType;
  298.             OSErr        err = GetFlavorType(fCurrentDrag, fCurrentDragItemRefNumber, dragFlavorIndex, &theType);
  299.             TempODValueType isoType = kODNULL;
  300.             isoType = translation->GetISOTypeFromPlatformType(ev, theType, kODPlatformDataType);
  301.             fSU->Focus(ev, kODPropContents, kODPosUndefined, kODNULL,
  302.                       0, kODPosUndefined);
  303.             StorageUnitSetPromiseValue(fSU, ev, isoType, 0,
  304.                                         sizeof(ItemReference), &fCurrentDragItemRefNumber, kODNULL);
  305.             // ODDisposePtr(isoType);   // No longer needed because it is now temp.
  306.             // If theType is 'styl', add a promise for 'stxt'
  307.             if ( theType == kODScrapTypestyl )
  308.             {
  309.                 if ( DragItemHasFlavor(fCurrentDrag, fCurrentDragItemRefNumber, kODScrapTypeTEXT) &&
  310.                      !DragItemHasFlavor(fCurrentDrag, fCurrentDragItemRefNumber, kODScrapTypestxt) )
  311.                     StorageUnitSetPromiseValue(fSU, ev, kODApplestxt, 0,
  312.                                                sizeof(ItemReference), &fCurrentDragItemRefNumber, kODNULL);
  313.             }
  314.             else if (theType == flavorTypeHFS)
  315.             {
  316.                 TempODValueType isoType = translation->GetISOTypeFromPlatformType(ev, 
  317.                                             fHFSFlavorPtr->fileType, kODPlatformFileType);
  318.                 fSU->AddValue(ev, isoType);
  319.                 // ODDisposePtr(isoType);   // No longer needed because it is now temp.
  320.             }
  321.         }
  322.     }
  323. }
  324.  
  325. //==============================================================================
  326. // ODMemDragItem
  327. //==============================================================================
  328. //------------------------------------------------------------------------------
  329. // ODMemDragItem::~ODMemDragItem
  330. //------------------------------------------------------------------------------
  331.  
  332. ODMemDragItem::~ODMemDragItem()
  333. {
  334.     ODSafeReleaseObject( fSU );
  335.     ODSafeReleaseObject( fDraft );
  336.     ODSafeReleaseObject( fDocument );
  337.     ODSafeReleaseObject( fContainer);
  338.     if( fContainerHandle != kODNULL)
  339.         ODDisposeHandle(fContainerHandle);
  340. }
  341.  
  342. //------------------------------------------------------------------------------
  343. // ODMemDragItem::Initialize
  344. //------------------------------------------------------------------------------
  345. void ODMemDragItem::Initialize(Environment* ev)
  346. {
  347.     ODDragItem::Initialize(ev);
  348.     
  349.     // Need to do this acquire so we will have the same number of releases
  350.     // whether the DragItem is used or not.
  351.     if( fDraft != kODNULL )
  352.         fDraft->Acquire(ev);
  353. }
  354.  
  355. //------------------------------------------------------------------------------
  356. // ODMemDragItem::Open
  357. //------------------------------------------------------------------------------
  358. void ODMemDragItem::Open(Environment* ev)
  359. {
  360.     if( fContainerHandle )
  361.     {
  362.         TRY
  363.             fContainer = AcquireMemoryContainer(ev, fStorageSystem->GetSession(ev), 
  364.                                             fContainerHandle, kODBentoMemoryContainer);
  365.             fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);
  366.             fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
  367.             TempODStorageUnit    draftProperties = fDraft->AcquireDraftProperties(ev);
  368.             fSU = fDraft->AcquireStorageUnit(ev, ODGetStrongSURefProp(ev, draftProperties,
  369.                                          kODPropRootPartSU, kODStrongStorageUnitRef));
  370.         CATCH_ALL
  371.             if (fSU != kODNULL)
  372.             {
  373.                 ODSafeReleaseObject( fSU );
  374.                 fSU = kODNULL;
  375.             }
  376.             if (fDraft != kODNULL)
  377.             {
  378.                 ODSafeReleaseObject( fDraft );
  379.                 fDraft = kODNULL;
  380.             }
  381.             if (fDocument != kODNULL)
  382.             {
  383.                 ODSafeReleaseObject( fDocument );
  384.                 fDocument = kODNULL;
  385.             }
  386.             if (fContainer != kODNULL)
  387.             {
  388.                 ODSafeReleaseObject( fContainer );
  389.                 fContainer = kODNULL;
  390.             }
  391.             if( fContainerHandle != kODNULL)
  392.                 ODDisposeHandle(fContainerHandle);
  393.             RERAISE;
  394.         ENDTRY
  395.     }
  396.     else if( fDraft )
  397.     {
  398.         fSU = fDraft->CreateStorageUnit(ev);
  399.     }
  400. }
  401.  
  402. //------------------------------------------------------------------------------
  403. // ODMemDragItem::Close
  404. //------------------------------------------------------------------------------
  405. void ODMemDragItem::Close(Environment* ev)
  406. {
  407.     ODSafeReleaseObject( fSU );
  408.     if (fDraft != kODNULL) {
  409.         fDraft->Externalize(ev);
  410.         ODSafeReleaseObject( fDraft );
  411.     }
  412.     ODSafeReleaseObject( fDocument );
  413.     ODSafeReleaseObject( fContainer );
  414. }
  415.  
  416.  
  417. //------------------------------------------------------------------------------
  418. // ODMemDragItem::GetStorageUnit
  419. //------------------------------------------------------------------------------
  420. ODStorageUnit*    ODMemDragItem::GetStorageUnit(Environment* ev)
  421. {
  422.     if( fSU == kODNULL )
  423.     {
  424.         TRY
  425.             Open( ev );
  426.                     
  427.             AddMacOSTypeInfoToSU(ev);        
  428.             AddFinderInfoToSU(ev);
  429.             
  430.         CATCH_ALL
  431.     #ifdef ODDebug_DragPriv
  432.             ODError err = ErrorCode();
  433.             WARN("Error in ODFileDragItem::Initialize");
  434.             char    errString[100];
  435.             numtostring(err, errString);
  436.             WARN(errString);
  437.     #endif
  438.             if (fSU != kODNULL)
  439.             {
  440.                 ODSafeReleaseObject( fSU );
  441.                 fSU = kODNULL;
  442.             }
  443.             if (fDraft != kODNULL)
  444.             {
  445.                 ODSafeReleaseObject( fDraft );
  446.                 fDraft = kODNULL;
  447.             }
  448.             if (fDocument != kODNULL)
  449.             {
  450.                 ODSafeReleaseObject( fDocument );
  451.                 fDocument = kODNULL;
  452.             }
  453.             if (fContainer != kODNULL)
  454.             {
  455.                 ODSafeReleaseObject( fContainer );
  456.                 fContainer = kODNULL;
  457.             }
  458.             RERAISE;
  459.         ENDTRY
  460.     }
  461.     return fSU;
  462. }
  463.  
  464. //==============================================================================
  465. // ODFileDragItem
  466. //==============================================================================
  467.  
  468.  
  469. //------------------------------------------------------------------------------
  470. // ODFileDragItem::~ODFileDragItem
  471. //------------------------------------------------------------------------------
  472. ODFileDragItem::~ODFileDragItem()
  473. {
  474. #if ODDebug_DragPriv
  475.     somPrintf("~ODFileDragItem: %x %x %x %x\n", fSU, fDraft, fDocument, fContainer);
  476. #endif
  477.  
  478.     Environment* ev = somGetGlobalEnvironment();
  479.     
  480.     ODSafeReleaseObject( fSU );
  481.     ODSafeReleaseObject( fDraft );
  482.     ODSafeReleaseObject( fDocument );
  483.     ODSafeReleaseObject( fContainer );
  484.     if (fContainerID)
  485.         DisposeByteArray(fContainerID);
  486. }
  487.  
  488. //------------------------------------------------------------------------------
  489. // ODFileDragItem::Initialize
  490. //------------------------------------------------------------------------------
  491. void ODFileDragItem::Initialize(Environment* ev, ODContainerID* containerID )
  492. {    
  493.     ODDragItem::Initialize(ev);
  494.     fContainerID = CopyByteArray(containerID);
  495. }
  496.  
  497. //------------------------------------------------------------------------------
  498. // ODFileDragItem::GetStorageUnit
  499. //------------------------------------------------------------------------------
  500. ODStorageUnit* ODFileDragItem::GetStorageUnit(Environment* ev)
  501. {
  502.     if (fSU == kODNULL)
  503.     {            
  504.     ODStorageUnitID    suid;
  505.     TempODContainerType containerType = kODNULL;    ODVolatile(containerType);
  506.     ODBoolean    shouldReleaseContainer = kODTrue;    ODVolatile(shouldReleaseContainer);
  507.         
  508.     TRY
  509.         containerType = GetContainerSuiteType((FSSpec*) fContainerID->_buffer);
  510.         fContainerID->_length = sizeof(short) + sizeof(long) + ((FSSpec*) fContainerID->_buffer)->name[0] + 1;
  511.         TRY
  512.             TempSuppressFatalBentoError tempSupressing;
  513.             fContainer = fStorageSystem->CreateContainer(ev, containerType, fContainerID);
  514.             fDocument = fContainer->AcquireDocument(ev, kODDefaultDocument);        
  515.             fDraft = fDocument->AcquireBaseDraft(ev, kODDPExclusiveWrite);
  516.             TempODStorageUnit    draftProperties = fDraft->AcquireDraftProperties(ev);
  517.             suid = ODGetStrongSURefProp(ev, draftProperties, kODPropRootPartSU, kODStrongStorageUnitRef);
  518.             fSU = fDraft->AcquireStorageUnit(ev, suid);
  519.         CATCH_ALL
  520.             // dh - There was a problem with the input container. We don't want to even touch it now,
  521.             // because Bento may well choke if we do, so do not release it below.
  522.             shouldReleaseContainer = kODFalse;
  523.             RERAISE;
  524.         ENDTRY    
  525.     
  526.         AddMacOSTypeInfoToSU(ev);
  527.         AddFinderInfoToSU(ev);
  528.             
  529.     #if ODDebug_DragPriv
  530.         somPrintf("ODFileDragItem::Initialize %x %x %x %x\n", fSU, fDraft, fDocument, fContainer);
  531.     #endif
  532.     
  533.     CATCH_ALL
  534.     #ifdef ODDebug_DragPriv
  535.         ODError err = ErrorCode();
  536.         WARN("Error in ODFileDragItem::Initialize");
  537.         char    errString[100];
  538.         numtostring(err, errString);
  539.         WARN(errString);
  540.     #endif
  541.  
  542.         if( shouldReleaseContainer )
  543.         {
  544.             if (fSU != kODNULL)
  545.             {
  546.                 ODSafeReleaseObject( fSU );
  547.                 fSU = kODNULL;
  548.             }
  549.             if (fDraft != kODNULL)
  550.             {
  551.                 ODSafeReleaseObject( fDraft );
  552.                 fDraft = kODNULL;
  553.             }
  554.             if (fDocument != kODNULL)
  555.             {
  556.                 ODSafeReleaseObject( fDocument );
  557.                 fDocument = kODNULL;
  558.             }
  559.             if (fContainer != kODNULL)
  560.             {
  561.                 ODSafeReleaseObject( fContainer );
  562.                 fContainer = kODNULL;
  563.             }
  564.         }
  565.         RERAISE;
  566.     ENDTRY
  567.     }
  568.     return fSU;
  569. }
  570.  
  571. //==============================================================================
  572. // ODDragLink
  573. //==============================================================================
  574. //------------------------------------------------------------------------------
  575. // ODDragLink::ODDragLink
  576. //------------------------------------------------------------------------------
  577. ODDragLink::ODDragLink(ODDragItem *theItem, ODBoolean cleanup)
  578. {
  579.     fItem = theItem;
  580.     fCleanup = cleanup;
  581. }
  582.  
  583. //------------------------------------------------------------------------------
  584. // ODDragLink::~ODDragLink
  585. //------------------------------------------------------------------------------
  586. ODDragLink::~ODDragLink()
  587. {
  588.     if (fCleanup)
  589.         delete fItem;
  590. }
  591.  
  592. //------------------------------------------------------------------------------
  593. // GetContainerSuiteType
  594. //------------------------------------------------------------------------------
  595.  
  596. ODContainerType    GetContainerSuiteType(FSSpec* fsSpec)
  597. {
  598. #if USE_GETCONTAINER_SUITE_TYPE
  599.     PlatformFile    file;
  600.     file.Specify(fsSpec);
  601.     
  602.     ODContainerType containerType = file.AcquireContainerType();
  603.     if (ODISOStrEqual(containerType, kODBentoFileContainer) || 
  604.         ODISOStrEqual(containerType, "")) {
  605.         containerType = kODBentoUpdateContainer;
  606.     }
  607. #else
  608.     ODULong len = strlen(kODBentoUpdateContainer);
  609.     ODContainerType containerType = (ODContainerType) ODNewPtr(len + 1);
  610.     strcpy(containerType, kODBentoUpdateContainer);
  611.     return containerType;
  612. #endif
  613. }
  614.  
  615. //------------------------------------------------------------------------------
  616. // GetFinderInfo
  617. //------------------------------------------------------------------------------
  618. void GetFinderInfo(Environment* ev, ODStorageUnit* su, PlatformFile* file)
  619. {
  620.     if (!file->IsDirectory())
  621.     {
  622.         ODTime creationDate = file->GetFileCreationDate();
  623.         ODSetCreationDate(ev, su, creationDate);
  624.         ODTime modDate = file->GetFileModDate();
  625.         ODSetModificationDate(ev, su, modDate);
  626.     
  627.         if (!file->IsStationery())
  628.         {    
  629.             ODName* name = file->GetName();
  630.             ODSetPONameUsingSU(ev, su, name);
  631.             DisposeIText(name);
  632.         }
  633.     
  634.         // Stationery bit is purposedly left out.
  635.     }
  636. }
  637.  
  638. //------------------------------------------------------------------------------
  639. // GetIconFamilyFromFile
  640. //------------------------------------------------------------------------------
  641. void GetIconFamilyFromFile(Environment* ev, ODStorageUnit* su, PlatformFile* file)
  642. {
  643.     if (!file->IsDirectory())
  644.     {
  645.         Handle iconFamily;
  646.         
  647.         short refNum = 0;
  648.         ODBoolean hasCustomIcon;
  649.         OSErr err = noErr;
  650.         ODVolatile(err);
  651.         TRY
  652.             hasCustomIcon = file->HasCustomIcon();
  653.             if (hasCustomIcon)
  654.             {
  655.                 file->SetPermission(fsRdPerm);
  656.                 refNum = CurResFile();
  657.                 err = ResError();
  658.                 if( err == noErr )
  659.                     file->OpenResFile();
  660.             }
  661.         CATCH_ALL
  662.             file->CloseResFile();
  663.             UseResFile(refNum);
  664.         ENDTRY
  665.         
  666.         if (hasCustomIcon && (err == noErr))
  667.         {        
  668.             err = GetIconSuite(&iconFamily, kCustomIconResource, svAllAvailableData);
  669.             if (err == noErr)
  670.             {
  671.                 ODSetIconFamilyProp(ev, su, kODPropCustomIcon, kODIconFamily, iconFamily, kODFalse);
  672.                 DisposeIconSuite(iconFamily, true);
  673.             }
  674. #ifdef ODDEBUG
  675.             else
  676.                 WARN("Problem getting icon family: %d ", err);
  677. #endif
  678.             file->CloseResFile();
  679.         }
  680.     }
  681. }
  682.  
  683.